﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WordMaster
{
    public partial class PageSetupMarginForm : Form
    {
        public PageSetupMarginForm()
        {
            InitializeComponent();
        }

        // 添加的任务
        public List<TaskInfo> Tasks = new List<TaskInfo>();

        // 常规 - 上下：2.54cm 左右：3.18cm
        private void btnPresetNormal_Click(object sender, EventArgs e)
        {
            nudTopMargin.Value = 2.54M;
            nudBottomMargin.Value = 2.54M;
            nudLeftMargin.Value = 3.18M;
            nudRightMargin.Value = 3.18M;
        }

        // 窄 - 上下左右：1.27cm
        private void btnPresetNarrow_Click(object sender, EventArgs e)
        {
            nudTopMargin.Value = 1.27M;
            nudBottomMargin.Value = 1.27M;
            nudLeftMargin.Value = 1.27M;
            nudRightMargin.Value = 1.27M;
        }

        // 适中 - 上下：2.54cm 左右：1.91cm
        private void btnPresetEqual_Click(object sender, EventArgs e)
        {
            nudTopMargin.Value = 2.54M;
            nudBottomMargin.Value = 2.54M;
            nudLeftMargin.Value = 1.91M;
            nudRightMargin.Value = 1.91M;
        }

        // 宽 - 上下：2.54cm 左右：5.08cm
        private void btnPresetWide_Click(object sender, EventArgs e)
        {
            nudTopMargin.Value = 2.54M;
            nudBottomMargin.Value = 2.54M;
            nudLeftMargin.Value = 5.08M;
            nudRightMargin.Value = 5.08M;
        }

        //
        private void btnOK_Click(object sender, EventArgs e)
        {
            //
            if(!HasChecked())
            {
                MessageBox.Show(
                    "请至少选中一项", "温馨提示", 
                    MessageBoxButtons.OK, 
                    MessageBoxIcon.Exclamation, 
                    MessageBoxDefaultButton.Button1);
                return;
            }

            //
            if (chkTopMargin.Checked)
            {
                Tasks.Add(new TaskInfo(
                    TaskTypes.PageSetupTopMargin,
                    "上边距",
                    "调整页边距：上边距=" + nudTopMargin.Value.ToString() + "厘米",
                    new object[] { Convert.ToSingle(nudTopMargin.Value) }));
            }

            //
            if (chkBottomMargin.Checked)
            {
                Tasks.Add(new TaskInfo(
                    TaskTypes.PageSetupBottomMargin, 
                    "下边距", 
                    "调整页边距：下边距=" + nudBottomMargin.Value.ToString() + "厘米",
                    new object[] { Convert.ToSingle(nudBottomMargin.Value) }));
            }

            //
            if (chkLeftMargin.Checked)
            {
                Tasks.Add(new TaskInfo(
                    TaskTypes.PageSetupLeftMargin,
                    "左边距",
                    "调整页边距：左边距=" + nudLeftMargin.Value.ToString() + "厘米",
                    new object[] { Convert.ToSingle(nudLeftMargin.Value) }));
            }

            //
            if (chkRightMargin.Checked)
            {
                Tasks.Add(new TaskInfo(
                    TaskTypes.PageSetupRightMargin,
                    "右边距",
                    "调整页边距：右边距=" + nudRightMargin.Value.ToString() + "厘米",
                    new object[] { Convert.ToSingle(nudRightMargin.Value) }));
            }

            //
            DialogResult = DialogResult.OK;
            Close();
        }

        // 是否有选中的项
        public bool HasChecked ()
        {
            return chkTopMargin.Checked || 
                chkBottomMargin.Checked || 
                chkLeftMargin.Checked || 
                chkRightMargin.Checked;
        }
    }
}
